package com.wn.class30.service.impl;

import com.wn.class30.entity.Business;
import com.wn.class30.entity.Myorder;
import com.wn.class30.entity.MyorderShare;
import com.wn.class30.mapper.BusinessDao;
import com.wn.class30.mapper.MyorderDao;
import com.wn.class30.mapper.MyorderShareDao;
import com.wn.class30.service.WXMyOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WXMyOrderServiceImpl implements WXMyOrderService {
    @Resource
    private MyorderDao myorderDao;
    @Resource
    private MyorderShareDao myorderShareDao;
    @Resource
    private BusinessDao businessDao;
    @Override
    public void updateShouhuo(Integer myOrderId) throws Exception {
        Myorder myorder = new Myorder();
        myorder.setMyorderId(myOrderId);
        myorder.setMyorderStatus(3);
        int i = myorderDao.updateByPrimaryKeySelective(myorder);
        Myorder myorder1 = myorderDao.selectByPrimaryKey(myOrderId);
        Business business = businessDao.selectByPrimaryKey(myorder1.getBussinessId());
        MyorderShare myorderShare = new MyorderShare();
        myorderShare.setBusinessName(business.getBusinessName());
        myorderShare.setBusinessId(myorder1.getBussinessId());
        myorderShare.setMyorderId(myorder1.getMyorderId());
        myorderShare.setMyorderNumber(myorder1.getMyorderNumber());
        myorderShare.setMyorderTotalPrice(myorder1.getMyorderTotalPrice());
        myorderShareDao.insertSelective(myorderShare);
    }

    @Override
    public void updateInitShouhuo() throws Exception {
        myorderDao.insertInitShouhuo();
        myorderDao.updateInitShouhuo();
    }
}
